package com.jiangyg.mall.coupon.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.coupon.dto.SeckillSkuNoticeDTO;
import com.jiangyg.mall.coupon.service.SeckillSkuNoticeService;
import com.jiangyg.mall.coupon.vo.SeckillSkuNoticeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：秒杀商品通知订阅控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-18 21:33:05
 */
@RestController
@RequestMapping("/coupon/seckill/sku/notice")
public class SeckillSkuNoticeController {

    /**
     * 秒杀商品通知订阅接口
     */
    private final SeckillSkuNoticeService seckillSkuNoticeService;

    @Autowired
    public SeckillSkuNoticeController(SeckillSkuNoticeService seckillSkuNoticeService) {
        this.seckillSkuNoticeService = seckillSkuNoticeService;
    }

    /**
     * 功能描述：秒杀商品通知订阅分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页秒杀商品通知订阅
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<SeckillSkuNoticeVO>> select(HttpServletRequest request, @RequestBody Pagination<SeckillSkuNoticeVO> pagination) throws Exception {
        return Result.ok(seckillSkuNoticeService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改秒杀商品通知订阅
     *
     * @param request 请求
     * @param dto     秒杀商品通知订阅
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated SeckillSkuNoticeDTO dto) throws Exception {
        return Result.saveOrUpdate(seckillSkuNoticeService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取秒杀商品通知订阅
     *
     * @param request 请求
     * @param seckillSkuNoticeId  秒杀商品通知订阅ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<SeckillSkuNoticeVO> info(HttpServletRequest request, @RequestParam(name = "seckillSkuNoticeId") Long seckillSkuNoticeId) throws Exception {
        return Result.ok(seckillSkuNoticeService.selectById(seckillSkuNoticeId));
    }

    /**
     * 功能描述：删除秒杀商品通知订阅
     *
     * @param request 请求
     * @param seckillSkuNoticeIds 批量删除的秒杀商品通知订阅ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestBody List<Long> seckillSkuNoticeIds) {
        return Result.delete(seckillSkuNoticeService.delete(seckillSkuNoticeIds));
    }

}
